package com.runa.monitor.platinterface.mqtt.vo;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Data
public class FourGPanelVO extends FourGVO {
    private String id;
    private String typ;
    private String nbattach1;
    private String nbr;
    private String nbdelay;
    private String rep;
    private String rrem;
    private String csq;
    private String icc;
    private String imei;
    private String rsrp;
    private String snr;
    private String eco;
    private String mver;
    private String T1;
    private String RH;
    private String etime;
    private String sta;
    private String ver;
    private String rtc;
    private String sitv1;
    private String uitv1;
    private String sitv2;
    private String uitv2;
    private String hot;
    private String bat;
    private String batv;
    private String life;
    private String Tc;
    private String Hc;
    private String reset;
    private String reperrcnt;
    private String rmc;
    private String nbi;
    private String LFDET;
    private String cenreptime;
    private String compile;

    public static void main(String[] args) {
        String s = "func:up,id:87654321,typ:3,nbattach1:15,nbr:8,nbdelay:2,rep:229,rrem:300,csq:0,icc: 89861123209093132072\n" +
                ",imei:864145075284354,rsrp:-99,snr:-1,eco:7F,mver:0,simf:0,4gmod: EC801ECNCGR03A08M02\n" +
                ",T1:[24.8,25.2,25.0,24.9,25.0,25.3,25.0,24.9,25.4,25.5,25.5,25.7,25.4,25.3,25.6,25.5,25.4,25.5],etime:20241113132340,sta:01,ver:1017,rtc:20241113132357,sitv1:5,uitv1:360,sitv2:10,uitv2:2880,hot:10010401,bat:3.610,batv:3.300,life:118286,Tc:0.0,Hc:0.0,reset:0,reperrcnt:0,rmc:10,nbi:1,LFDET:0,hrs:6,ahead:120,cenreptime:10,stf:1,stemp:0|23.0,stul:45.0,stdl:5.0,compile:2024-08-16T13-17-48";
        FourGPanelVO gene = FourGPanelVO.gene(s);
        System.out.println(JSON.toJSONString(gene));
    }

    @SneakyThrows
    public static FourGPanelVO gene(String json) {
        return generate(FourGPanelVO.class, json);
    }

    public String faultStr() {
        int st = Integer.parseInt(sta, 16);
        StringBuilder stringBuilder = new StringBuilder();
        if ((st & 1) == 1) {
            stringBuilder.append("挪动报警;");
        }
        int ec = Integer.parseInt(eco, 16);
        if ((ec & 1) == 0 && (ec >> 1 & 1) == 0) {
            stringBuilder.append("电池电量不足;");
        }
        if ((ec >> 2 & 1) == 0) {
            stringBuilder.append("未查询到NB模组CGSN码;");
        }
        if ((ec >> 3 & 1) == 0) {
            stringBuilder.append("未查询到SIM卡号;");
        }
        if ((ec >> 4 & 1) == 0) {
            stringBuilder.append("网络未附着成功;");
        }
        if ((ec >> 5 & 1) == 0) {
            stringBuilder.append("发送数据失败;");
        }
        if ((ec >> 6 & 1) == 0) {
            stringBuilder.append("未接收到数据;");
        }
        return stringBuilder.toString();
    }
    public String wakeUpCycle(boolean heatingPeriod) {
        return heatingPeriod ? uitv1 : uitv2;
    }

}
